package org.example.mqactual.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

public class MqClientInstances {

    public static void main(String[] args) throws Exception {
        // 第一个生产者
        DefaultMQProducer producer1 = new DefaultMQProducer("ExampleProducerGroup1");

        // 第二个生产者
        DefaultMQProducer producer2 = new DefaultMQProducer("ExampleProducerGroup2");
        //设置clientId
        producer2.setNamesrvAddr("xxx");
        producer2.setUnitName("DefaultClusterb");
        producer2.start();
        producer1.setNamesrvAddr("127.0.0.1:9876");
        // 启动生产者
        producer1.start();
        int totalMessagesToSend = 10;
        for (int i = 0; i < totalMessagesToSend; i++) {
            Message message = new Message("test", ("Hello scheduled message " + i).getBytes());
            // 设置延时等级3,这个消息将在10s之后发送(现在只支持固定的几个时间,详看delayTimeLevel)
            message.setDelayTimeLevel(19);
            // 发送消息
            producer1.send(message);

        }
        // 关闭生产者
        producer1.shutdown();
    }
}
